<?php
declare (strict_types = 1);

namespace app\middleware;

use thans\jwt\facade\JWTAuth;

class MsgLoginHttp
{

    public function handle($request, \Closure $next){
        try {
            $token_obj = JWTAuth::auth();//验证token
        } catch (\Exception $e){
            return error_json($e->getMessage(),[],-1000);
        }
        $token_obj = json_decode(json_encode($token_obj),true);
        if(!isset($token_obj['adminid']) || !$token_obj['adminid']){
            return error_json('未获取到用户信息');
        }
        //方便后面使用
        $request->adminid = $token_obj['adminid'];
        $request->admin_groupid = $token_obj['admin_groupid'];

        return $next($request);
    }
}
